package com.zs.oauth2.common.service.security;

import com.zs.oauth2.common.core.constant.CacheConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.oauth2.common.exceptions.InvalidClientException;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;

import javax.sql.DataSource;

/**
 * @author madison
 * @description
 * @date 2021/4/5 04:25
 */
@Slf4j
public class Oauth2ClientDetailsService extends JdbcClientDetailsService {
    public Oauth2ClientDetailsService(DataSource dataSource) {
        super(dataSource);
    }

    @Override
    @Cacheable(value = CacheConstants.CLIENT_DETAILS_KEY, key = "#clientId", unless = "#result == null")
    public ClientDetails loadClientByClientId(String clientId) throws InvalidClientException {
        log.info("======Oauth2ClientDetailsService.loadClientByClientId======:{}", clientId);
        return super.loadClientByClientId(clientId);
    }
}
